<?php defined('SYSPATH') or die('No direct script access.');

class Model_Action extends ORM
{ 
    protected $_reload_on_wakeup = false;
    
    public function get_actions($shop = null, $count = false)
    {                
        $shop_id = $shop;
        if ($shop instanceof Model_Shop) {
            $shop_id = $shop->id;    
        }
        
        if ($actions = Cache::instance()->get('actions_'.$shop_id.'_'.$count)) {
            return $actions;
        }
         
        $query = ORM::factory('action'); 
        
        if (!is_null($shop_id)) {
            $query->where('shop_id', '=', $shop_id);    
        }
        
        if ($count) {
            $result = $query->count_all();
            Cache::instance()->set('actions_'.$shop_id.'_'.$count, $result);
            return $result;
        } 
        
        $query->order_by('id', 'ASC');      
        
        $actions = $query->find_all()->as_array();  
        Cache::instance()->set('actions_'.$shop_id.'_'.$count, $actions); 
        return $actions;
    } 
}